/**
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2009，所有权利保留。
 * 
 * 项目名：	rumba-widget2
 * 文件名：	RTextAlign.java
 * 模块说明：	
 * 修改历史：
 * Jan 23, 2009 - lxm - 创建。
 */
package com.hd123.rumba.gwt.widget2.client.misc;

import com.google.gwt.user.client.ui.TextBoxBase;

/**
 * 枚举：文本对齐方式。
 * 
 * @author lxm
 * 
 */
public class RTextAlign {

  public static final RTextAlign left = new RTextAlign("left");
  public static final RTextAlign right = new RTextAlign("right");
  public static final RTextAlign center = new RTextAlign("center");
  public static final RTextAlign justify = new RTextAlign("justify");

  private RTextAlign(String styleText) {
    super();
    this.styleText = styleText;
  }

  private String styleText;

  public String getStyleText() {
    return styleText;
  }

  public static RTextAlign valueOf(String styleText) {
    if (styleText == null)
      return null;
    if (styleText.equals(left.getStyleText()))
      return left;
    if (styleText.equals(right.getStyleText()))
      return right;
    if (styleText.equals(center.getStyleText()))
      return center;
    if (styleText.equals(justify.getStyleText()))
      return justify;
    return null;
  }

  public static RTextAlign valueOf(TextBoxBase.TextAlignConstant textAlign) {
    if (textAlign == TextBoxBase.ALIGN_LEFT)
      return left;
    else if (textAlign == TextBoxBase.ALIGN_RIGHT)
      return right;
    else if (textAlign == TextBoxBase.ALIGN_CENTER)
      return center;
    else if (textAlign == TextBoxBase.ALIGN_JUSTIFY)
      return justify;
    return null;
  }
  
  public TextBoxBase.TextAlignConstant toTextAlign() {
    if (this == left)
      return TextBoxBase.ALIGN_LEFT;
    else if (this == right)
      return TextBoxBase.ALIGN_RIGHT;
    else if (this == center)
      return TextBoxBase.ALIGN_CENTER;
    else if (this == justify)
      return TextBoxBase.ALIGN_JUSTIFY;
    return null;
  }
}
